package com.hyb.algorithm.data.struct.str;

/**
 * @author: ybhu
 * @create: 2021/09/21 15:20
 *
 * 58. 最后一个单词的长度
 * https://leetcode-cn.com/problems/length-of-last-word/
 *
 *
 */
public class LengthOfLastWord {


    public int lengthOfLastWord(String s) {
        int index=s.length()-1;
        while(s.charAt(index)==' '){
            index--;
        }

        int wordIndex=0;
        while(index>=0&&s.charAt(index)!=' '){
            index--;
            wordIndex++;
        }

        return wordIndex;
    }
}
